//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "framework\fn_updateMarker.sqf"
#include <tmf_constants.h>
#include <tmf_macros.h>

TRACE_1("Start",_this);
TMFPROFILERSTART;

private ["_is_server_only","_marker_params","_marker_name","_delete_marker","_i","_marker_pos","_current_marker","_mission_markers","_title"];
DEFAULT_PARAM(_object,TMF_EXECUTE_ACTION_OBJECT,objNull);
	
	// _is_server_only = _this select 0;
	// _marker_params = _this select 1;
	// _marker_name = _marker_params select 0;
	// _delete_marker= (count _marker_params == 1);
	// if (d_mission_debug_messages) then { diag_log Format["(%1)[%2]: %3: %4 => %5",diag_tickTime,"mission_functions.sqf","XfMissionUpdateMarker","Adding marker",_this];};
	// if (_is_server_only && !d_mission_debug_messages) then {
		// // Hides the marker in case someone is hosting the game on his computer otherwise he sees it.
		// if (count _marker_params >= 10) then { _marker_params set [10, 0.0000001]; };
	// };
	// If (X_Server) then {
		// // If the marker needs to be synchronized in JIP, we add/update it in the JIP list.
		// if (!_is_server_only) then {
			// _mission_markers = ["current_mission_markers",[]] call XNetGetJIP;
			// _marker_pos = -1;
			// If ((count _mission_markers)>0) then {
				// for [{_i = 0},{_i < count _mission_markers},{_i = _i + 1}] do {
					// _current_marker = _mission_markers select _i;
					// if (str(_current_marker select 0) == str(_marker_name)) exitWith{_marker_pos = _i};
				// };
			// };
			// if (_marker_pos < 0) then {
				// _mission_markers set [count _mission_markers, [_marker_name,_marker_params]];
			// } else {
				// _mission_markers set [_marker_pos, [_marker_name,_marker_params]];
			// };
			// ["current_mission_markers",_mission_markers] call XNetSetJIP;
			// if (d_mission_debug_messages) then { diag_log Format["(%1)[%2]: %3: %4 (%5)",diag_tickTime,"mission_functions.sqf","XfMissionUpdateMarker","Added marker to JIP",(count _mission_markers)];};
		// };
		// // We add this check for when we test the mission in the editor. Then the marker got create on the Client anyway.
		// if ((!X_Client) OR _is_server_only) then {
			// _marker_created_pos = -1;
			// if (count d_mission_marker_list	> 0) then {
				// for [{_i = 0},{_i < count d_mission_marker_list},{_i = _i + 1}] do {
					// _current_marker = d_mission_marker_list select _i;
					// if (str(_current_marker) == str(_marker_name)) exitWith{_marker_created_pos = _i};
				// };			
			// };
			// if (_delete_marker) then {
				// If (_marker_created_pos > 0) then {
					// d_mission_marker_list set [_marker_created_pos,"XfXXDEL"];
					// d_mission_marker_list = d_mission_marker_list - ["XfXXDEL"];
					// if (d_mission_debug_messages) then { diag_log Format["(%1)[%2]: %3: %4 (%5)",diag_tickTime,"mission_functions.sqf","XfMissionUpdateMarker","Removed from server list",_marker_name];};
				// };			
				// if (d_mission_debug_messages) then { diag_log Format["(%1)[%2]: %3: %4 (%5)",diag_tickTime,"mission_functions.sqf","XfMissionUpdateMarker","Deleting server marker",_marker_name];};
				// deleteMarkerLocal _marker_name;
			// } else {
				// If (_marker_created_pos < 0) then {
					// _marker_params call XfCreateMarkerLocal;
					// d_mission_marker_list set [count d_mission_marker_list,_marker_name];
					// if (d_mission_debug_messages) then { diag_log Format["(%1)[%2]: %3: %4 (%5)",diag_tickTime,"mission_functions.sqf","XfMissionUpdateMarker","Creating server marker",_marker_name];};
				// } else {		
					// _marker_params call XfUpdateMarkerLocal;
					// if (d_mission_debug_messages) then { diag_log Format["(%1)[%2]: %3: %4 (%5)",diag_tickTime,"mission_functions.sqf","XfMissionUpdateMarker","Updating server marker",_marker_name];};
				// };			
			// };
		// };
	// };
	// If (X_Client AND (!_is_server_only)) then {
		// _marker_created_pos = -1;
		// if (count d_mission_marker_list	> 0) then {
			// for [{_i = 0},{_i < count d_mission_marker_list},{_i = _i + 1}] do {
				// _current_marker = d_mission_marker_list select _i;
				// if (str(_current_marker) == str(_marker_name)) exitWith{_marker_created_pos = _i};
			// };			
		// };
		// if (_delete_marker) then {
			// If (_marker_created_pos > 0) then {
				// d_mission_marker_list set [_marker_created_pos,"XfXXDEL"];
				// d_mission_marker_list = d_mission_marker_list - ["XfXXDEL"];
				// if (d_mission_debug_messages) then { diag_log Format["(%1)[%2]: %3: %4 (%5)",diag_tickTime,"mission_functions.sqf","XfMissionUpdateMarker","Removed from client list",_marker_name];};
			// };			
			// if (d_mission_debug_messages) then { diag_log Format["(%1)[%2]: %3: %4 (%5)",diag_tickTime,"mission_functions.sqf","XfMissionUpdateMarker","Deleting client marker",_marker_name];};
			// deleteMarkerLocal _marker_name;
		// } else {
			// If (_marker_created_pos <= 0) then {
				// _marker_params call XfCreateMarkerLocal;
				// d_mission_marker_list set [count d_mission_marker_list,_marker_name];
				// if (d_mission_debug_messages) then { diag_log Format["(%1)[%2]: %3: %4 (%5)",diag_tickTime,"mission_functions.sqf","XfMissionUpdateMarker","Creating client marker",_marker_name];};
			// } else {
				// _marker_params call XfUpdateMarkerLocal;
				// if (d_mission_debug_messages) then { diag_log Format["(%1)[%2]: %3: %4 (%5)",diag_tickTime,"mission_functions.sqf","XfMissionUpdateMarker","Updating client marker",_marker_name];};
			// };			
		// };
	// };

TRACE("End");
TMFPROFILERSTOP;